const http = require('https');
const fs = require('fs');
const path = require('path');
const shopList = require('./shopList.js');
const banner = require('./banner.js');
function downloadImg(url, name) {
  const remoteImageUrl = url;
  const localFolderPath = './download';
  const fileName = name;
  const file = fs.createWriteStream(path.join(localFolderPath, fileName));
  return new Promise((resolve, reject) => {
    http
      .get(remoteImageUrl, (response) => {
        response.pipe(file);
        file.on('finish', () => {
          file.close(resolve(true));
        });
      })
      .on('error', (error) => {
        fs.unlink(path.join(localFolderPath, fileName));
        reject(error.message);
      });
  });
}

shopList.forEach(async (item) => {
  await downloadImg(item.icon, `${item.id}-icon.png`);
  await downloadImg(item.shop_image, `${item.id}-shop.png`);
});
